import { createApp } from 'vue'
import {router} from "./router/index.js";
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import {createPinia} from 'pinia'
import axios from 'axios'
import App from './App.vue'

const app = createApp(App)
app.use(ElementPlus)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
const pinia=createPinia()
app.use(pinia)
app.use(router)
//将axios进行全局设置
app.config.globalProperties.$axios = axios
// 是否在启动时生成生产提示
app.config.productionTip = false
// 指定 axios 的全局配置，指定为后端服务器地址
axios.defaults.baseURL = 'http://localhost:8080/'
// 指定 axios 的请求头中携带 cookie
axios.defaults.withCredentials = true;

// 添加 axios 请求的拦截器
axios.interceptors.request.use(config => {
    const token = localStorage.getItem('token');
    if (token) {
        config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
}, error => {
    return Promise.reject(error);
});
//定义图片地址全局变量，所有组件都可以使用
app.config.globalProperties.$urlImage = 'http://localhost:8080/images/';
app.mount('#app')
